//p1364
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
typedef long long ll;
const ll INF=1ll<<60;//很大的一个数
ll n,ans=INF,tmp;
bool vis[1001];
struct tree
{
	std::vector<ll>to;
	ll w;
}t[1001];
void start()
{
	scanf("%lld",&n);
	ll l,r;
	for(ll i=1;i<=n;++i)
	{
		scanf("%lld%lld%lld",&t[i].w,&l,&r);
		if(l)t[l].to.push_back(i),t[i].to.push_back(l);
		if(r)t[r].to.push_back(i),t[i].to.push_back(r);
	}
}
ll dfs(ll u,ll step)
{
	ll res=step*t[u].w;
	vis[u]=1;
	for(ll i=t[u].to.size()-1;i>=0;--i)
	{
		if(!vis[t[u].to[i]])res+=dfs(t[u].to[i],step+1);
	}
	return res;
}
int main()
{
	start();
	for(ll i=1;i<=n;++i)
	{
		memset(vis,0,sizeof(vis));
		tmp=dfs(i,0);
		if(tmp<ans)ans=tmp;
	}
	printf("%lld",ans);
	return 0;
}
